package greatwall.myreader;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.mortbay.jetty.security.ClientCertAuthenticator;

import com.iximo.domain.Book;
import com.iximo.openAPI.impl.IximoOpenAPIGetImpl;
import com.iximo.util.OpenAPIClient;

import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class Book_Detail_info extends Activity 
{
	private  TextView Author_book;
	private  TextView Titlle_bookdetail;
	private  TextView Hint_book;
	private  TextView Total_count;
	private  TextView Upate_date;
	private  TextView Short_intruction;
	private  Button   Download;
	private  Button   List_item;
	private  Button   Read_online;
	//private  Button   Add_Restore;
	private  ImageView short_image;
	private IximoOpenAPIGetImpl Get = new IximoOpenAPIGetImpl();
	private OpenAPIClient XiMoClient = OpenAPIClientFactory.GetInstance();
	//在此Activity被激活时所执行的一些初始化操作
	@Override
    public    void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.book_detail);
        //把本Activity中定义的控件和页面的对应控件连接起来
        Titlle_bookdetail=(TextView)findViewById(R.id.title);
        Author_book=(TextView)findViewById(R.id.author);
        Hint_book=(TextView)findViewById(R.id.visitor);
        Total_count=(TextView)findViewById(R.id.wordsize);
        Upate_date=(TextView)findViewById(R.id.updatetime);
        Short_intruction=(TextView)findViewById(R.id.textView1);
        Download=(Button)findViewById(R.id.download);
        List_item=(Button)findViewById(R.id.mulu);
        Read_online=(Button)findViewById(R.id.read_online);
//        Add_Restore=(Button)findViewById(R.id.addcollect);
        short_image=(ImageView)findViewById(R.id.imageView1);
        //获取并在页面显示书籍的相关信息
        Display_Book_info();
        List_item.setOnClickListener(List_item_show);
    }
	
	//获取书籍的ID(String 类型)
	private String GetbookID()
	{
		//接受ShowCategoryNameList 的Intent
		Intent intent=this.getIntent();
		//获取Intent中的关键字是 getString的字符串
		String getstring=intent.getStringExtra("getString");
		return getstring ;
	}
	
	//“目录”按钮的点击事件
	private OnClickListener List_item_show = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent_item=new Intent();
			intent_item.putExtra("BookID",GetbookID());
			intent_item.setClass(Book_Detail_info.this,Getchapter.class);
			startActivity(intent_item);
		}
};
  	//在页面上显示对应的内容
	private void Display_Book_info()
	{
		try
		{
			//调用吸墨的API根据获取到的ID 获取对应书籍的信息
			String book_info=XiMoClient.get_book_info(Integer.parseInt(GetbookID()), "");
			InputStream inputStream = new ByteArrayInputStream(book_info.getBytes());
			Book   book=Get.getBookInfoData(inputStream);
			//获取到的信息对应的显示在界面上
			Author_book.setText("作者: "+book.getAuthor());
			Hint_book.setText("点击量： "+book.getHitCount());
			Total_count.setText("字数统计："+book.getWords());
			Upate_date.setText("更新日期： "+book.getCollectTime());
			Titlle_bookdetail.setText(book.getTitle());
			Short_intruction.setText(book.getDesc());
		}
		catch (Exception e) 
		{
			// TODO: handle exception
			Log.i("Book_Detail_info", "获取不到数据");
		}	
	}
}
